<?php
class HttpData
{
    public static function result($type, $code, $msg, $data, $cache = 0)
    {
        global $Cache;
        if ($type == 'json') {
            header('Content-Type: application/json');
        } else if ($type == 'xml') {
            header('Content-Type: text/xml');
        } else if ($type == 'html') {
            header('Content-Type: text/html');
        }
        $result = array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
            'time' => time() + $cache,
            'type' => $type
        );
        if ($cache > 0) {
            // 写入文件
            Cache::set(json_encode($_GET), $result, $cache);
        }
        return $result;
    }
}

$respone = new HttpData();
